import { Record, List } from 'immutable';
import generateId from '../../utils/generate-id';

const DEFAULTS = {
  name: undefined,
  type: undefined,
  defaultValue: undefined,
  id: undefined
};
export default class APIParam extends Record(DEFAULTS) {
  static create(attr = {}) {
    const { name, type = 'string', defaultValue, id = generateId() } = attr;
    return new APIParam({
      name,
      type,
      defaultValue,
      id
    });
  }

  static createList(attr = []) {
    if (List.isList(attr) || Array.isArray(attr)) {
      return List(attr.map(APIParam.create));
    }
  }
}
